package com.lollipop.common.persistence;

import com.lollipop.common.utils.PropertiesUtils;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.beans.Transient;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

@Getter
@Setter
public abstract class BaseModel<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    protected String id;

    protected transient Map<String, Object> extraArgs = new HashMap<String, Object>();

    public String getDbName() {
        return PropertiesUtils.readDefaultFile().getString("jdbc.type");
    }

    public boolean isNew() {
        return StringUtils.isBlank(getId());
    }

    public void setArgs(String argName, Object argValue) {
        this.extraArgs.put(argName, argValue);
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
    }
}
